
use		"./output/intermediate/citiescls_patents_19001929", clear

order pat_*, alpha
order cls_id f_myr, first

merge m:1 cls_id using "./output/intermediate/cls_excessmortality_exp"
drop if _merge!=3
drop	_merge

xtset  	cls_id f_myr

gen		f_yr = year(dofm(f_myr))
gen		f_m = month(dofm(f_myr))

** Interpolate population data ** 

gen		pop_int_0010 = pop_1900 + (f_myr-tm(1900m4))*(pop_1910-pop_1900)/120
gen		pop_int_1020 = pop_1910 + (f_myr-tm(1910m4))*(pop_1920-pop_1910)/120
gen		pop_int_2030 = pop_1920 + (f_myr-tm(1920m4))*(pop_1930-pop_1920)/120

gen		pop_int = pop_int_0010
replace	pop_int = pop_int_1020 if tin(1910m5,1920m4)
replace	pop_int = pop_int_2030 if tin(1920m5,1930m4)

lab var pop_int "Interpolated population (monthly using '00,'10,'20,'30 census pops)"

drop	pop_int_???? pop_19??

foreach v in first_inv all_inv wtd_inv single_inv multinvs_inv multpats_inv {
	gen prate_`v' = pat_`v'/(pop_int/100000)
	gen prate_`v'_noassg = pat_`v'_noassg/(pop_int/100000)
	gen prate_`v'_wassg = pat_`v'_wassg/(pop_int/100000)
} // Missing values are cities for which population could not be found in particular decade(s)

compress

save 	"./output/cities_clspatents", replace
clear
